package oss

import (
	"context"
	"net/url"
	"time"

	"github.com/minio/minio-go/v7"
	"github.com/minio/minio-go/v7/pkg/notification"
)

type MinioBucket struct {
	name   string
	client *minio.Client
}

type BucketManager interface {
	PresignedPutObject(ctx context.Context, key string, expires time.Duration) (*url.URL, error)
	PresignedGetObject(ctx context.Context, key string, expires int64, req url.Values) (*url.URL, error)
	SetBucketNotification(ctx context.Context, config notification.Configuration) error
	GetBucketNotification(ctx context.Context) (notification.Configuration, error)
}

func (b *MinioBucket) PresignedPutObject(
	ctx context.Context, key string, expires time.Duration,
) (u *url.URL, err error) {
	return b.client.PresignedPutObject(ctx, b.name, key, expires)
}

func (b *MinioBucket) PresignedGetObject(
	ctx context.Context, key string, expires int64, req url.Values,
) (u *url.URL, err error) {
	return b.client.PresignedGetObject(ctx, b.name, key, time.Duration(expires), req)
}

func (b *MinioBucket) SetBucketNotification(ctx context.Context, config notification.Configuration) error {
	return b.client.SetBucketNotification(ctx, b.name, config)
}

func (b *MinioBucket) GetBucketNotification(ctx context.Context) (notification.Configuration, error) {
	return b.client.GetBucketNotification(ctx, b.name)
}
